/* 
 *   WWW.COO8.COM  
 */

package com.gm.memberShip.menu.controller.action;
import com.gm.common.utils.UtilCookieMD5;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import java.util.*;

import org.apache.commons.lang.StringUtils;
 

import com.gm.memberShip.menu.model.*;
import com.gm.memberShip.menu.persistence.interfaces.*;
import com.gm.memberShip.menu.business.interfaces.*;  

/**
 * @author  JIANGCHENG
 * @version 1.0
 * @since 1.0
 */


@Namespace("/Users")
public class UsersAction extends UsersBaseAction { 

	protected static final String DEFAULT_SORT_COLUMNS = null; 
	
	 
	    
	@Action(value="list",results={@Result(name="success",location="/")})
	public String list() {
		return "success";
	}
	
	@Action(value="show",results={@Result(name="success",location="/")}) 
	public String show() {
		return "success";
	}
	
	@Action(value="create",results={@Result(name="success",location="/")})
	public String create() {
		return "success";
	}
	
	@Action(value="save",results={@Result(name="success",location="/")})
	public String save() {
		System.out.print(users);
		users=new Users();
		 
		usersManager.save(users);
		System.out.print("sssss");
		return "success";
	}
	
	@Action(value="edit",results={@Result(name="success",location="/")})
	public String edit() {
		return "success";
	}
	
	@Action(value="update",results={@Result(name="success",location="/")})
	public String update() {
		usersManager.update(this.users);
		return "success";
	}
 
    @Action(value="delete",results={@Result(name="success",location="/")})
	public String delete() {
	    return "success";
	}
    @Action(value="loginCheck",results={@Result(name="success",location="/framework.jsp"),@Result(name="error",location="/index.jsp")})
	public String loginCheck() {
    	 
    	if(userName!=null&&password!=null){ 
    		password=UtilCookieMD5.md5(password);
    		HashMap search=new HashMap();
    		search.put("userName",userName);
    		search.put("password",password);
    		List<Users> userList=usersManager.loginCheck(search);
        	if(userList!=null&&userList.size()>0){
        		System.out.print(userList.size());
        	    Users users=userList.get(0);
        		this.getSession().setAttribute("userName",users.getUserName());
        		this.getSession().setAttribute("userId", users.getUserId());
        		
        		List<Module> moduleList=moduleManager.findMemubyUserId(users.getUserName());
        		
        		return "success";
        	}else{
        		return "error";
        	} 
    	}else{
    		return "error";
    	}
    		
    	
	}
    @Action(value="checkUser")
	public void checkUser() {
    	if(userName!=null&&password!=null){ 
    		password=UtilCookieMD5.md5(password);
    		HashMap search=new HashMap();
    		search.put("userName",userName);
    		search.put("password",password);
    		List<Users> userList=usersManager.loginCheck(search);
        	if(userList!=null&&userList.size()>0){
        		System.out.print(userList.size());
        	    Users users=userList.get(0);
        		this.getSession().setAttribute("userName",users.getUserName());
        		this.getSession().setAttribute("userId", users.getUserId());
        		
        		List<Module> moduleList=moduleManager.findMemubyUserId(users.getUserName());
        		
        	 
        	}else{
        		 
        	} 
    	}else{
    		 
    	}
    		
    	this.writeAjaxResponse("");
	}
    
    @Action(value="logOut",results={@Result(name="success",location="/index.jsp")})
	public String logOut() {
    	this.getSession().setAttribute("userName", "");
    	this.getSession().setAttribute("userId",""); 
    	return "success";
    		
    	
	}
    public void getFunclist(){
    	
    	
    }
    public void getArea(){
    	
    }

}
